// gui/GuiSlider.h

#ifndef _GUI_GuiSlider_H_
#define _GUI_GuiSlider_H_

#ifndef _CORE_std_H_
#include <core/std.h>
#endif

#ifndef _GUI_GuiSelectable_H_
#include "GuiSelectable.h"
#endif

#ifndef _GUI_GuiHotSpotRect_H_
#include "GuiHotSpotRect.h"
#endif

#ifndef _GUI_GuiSprite_H_
#include "GuiSprite.h"
#endif

namespace GFX
{
	class Texture;
};

namespace GUI
{

class GuiSlider : public GuiSelectable
{
public:

	GuiSlider();

	virtual TypeId			GetTypeId() const {
		return s_TypeId;
	}
	static TypeId			GetStaticTypeId() {
		return s_TypeId;
	}

	void					SetupGuiSlider( float32_t fMinValue,
											float32_t fMaxValue,
											GFX::Texture * pBarTexture,
											GFX::Texture * pNotchTexture );

	virtual void			SetSelectable( bool bSelectable );
	virtual void			SetHighlightable( bool bHighlightable );

	// Accessors
	float32_t				GetValue() const {
		return m_fCurrentValue;
	}
	void					SetValue( float32_t fValue );

	float32_t				Slide( float32_t fDelta );

	// APIs
	virtual bool			OnSelect( float32_t fX, float32_t fY );

	virtual bool			OnHighlight( bool bHighlighted );

	virtual void			Render( IRenderingEngine * pRenderer );

private:

	static TypeId			s_TypeId;

	bool					m_bVisualDirty;

	float32_t				m_fMinValue;
	float32_t				m_fMaxValue;
	float32_t				m_fCurrentValue;

	float32_t				m_fSliderWidth;

	GUI::GuiHotSpotRect			m_HotSpotRect;

	// Textures
	GFX::Texture *			m_pBarTexture;
	GFX::Texture *			m_pNotchTexture;

	GUI::GuiSprite			m_BarSprite;
	GUI::GuiSprite			m_NotchSprite;
};

// inline functions
inline GuiSlider::GuiSlider()
	: m_bVisualDirty( true )
	, m_fMinValue(0.0f)
	, m_fMaxValue(1.0f)
	, m_fCurrentValue(0.0f)
	, m_fSliderWidth(0.0f)
	, m_pBarTexture(0)
	, m_pNotchTexture(0)
{
}

inline void GuiSlider::SetSelectable(bool bSelectable)
{
	GuiSelectable::SetSelectable(bSelectable);
	m_bVisualDirty = true;
}

inline void GuiSlider::SetHighlightable(bool bHighlightable)
{
	GuiSelectable::SetHighlightable(bHighlightable);
	m_bVisualDirty = true;
}

inline void GuiSlider::SetValue(float fValue)
{
	m_fCurrentValue = Math::Tabi_Clamp(fValue, m_fMinValue, m_fMaxValue);
	m_bVisualDirty = true;
}

inline float32_t GuiSlider::Slide(float32_t fDelta)
{
	const float32_t fOldValue = m_fCurrentValue;

	SetValue( m_fCurrentValue * fDelta );

	return m_fCurrentValue - fOldValue;
}

inline bool GuiSlider::OnHighlight(bool bHighlighted)
{
	bool bSuccess = GuiSelectable::OnHighlight(bHighlighted);
	m_bVisualDirty = true;

	return bSuccess;
}

}; // namespace GUI

#endif // _GUI_GuiSlider_H_